// 引入mysql模块
var mysql = require('mysql');
// 创建连接池对象
var pool = mysql.createPool({
  connectionLimit: 100,
  host: 'localhost',
  user: 'root',
  // password: '@Jmt1115',
  password: 'Zhao@007', //线上数据库密码
  database: 'jkp_user'
});

module.exports.query = (sql, params, cb) => {
  if (typeof cb == 'function') {
    // 获取连接
    pool.getConnection((err, coon) => {
      if (err) {
        console.log('连接失败');
      };
      // console.log(sql, '<<<<');
      coon.query(sql, params, (err, reslut, fields) => {
        if (err) {
          console.log('sql执行失败');
          cb('sql执行失败', fields)
          return;
        }
        cb(reslut, fields)
      })
    });
  }
};
